function createXMLHttp(){
    var xmlHttp=null;
    try{
        xmlHttp=new XMLHttpRequest();
    }
    catch(e){
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
     }
     return xmlHttp;
};
function emailvalid(str){
    var myRegExp = /[a-z0-9-.]{1,30}@[a-z0-9-]{1,65}.(com|net|org|info|biz|([a-z]{2,3}.[a-z]{2}))/ ;
    return myRegExp.test(str);
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function createcookie(name, value, days){
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else 
        var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function page_size(){
    var value = document.getElementById('pagesize').value;
    createcookie('pagesize', value);
    window.location.href = document.URL;
}
function getcookie(name){

    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) 
            return null;
    }
    else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function filter_show(url)
{
	window.location.href = url + document.getElementById('filter').value;	
}
function reload_url_current()
{
	window.location.href = document.URL;	
}
function checkall(n )
{
	var f = document.adminForm;

	fname = "cbk";
	
	for (i=0; i < n; i++) 
	{		
		var	cb = eval( 'f.' + fname + '' + i );
		if(f.toggle.checked == true)
			cb.checked = true; 			
		else
			cb.checked = false;
	}
}
function reloadadmin(url , type)
{
	if(type==1)
	{
		if(!confirm("Bạn có thực sự muốn xóa"))	
			return false;
	}
	
	var http = createXMLHttp();		
	
	http.onreadystatechange=function()
	{ 	
		if(http.readyState==4) 		
			window.location.href = document.URL;	             
	}
	
	http.open("GET",url,true);
 	http.send(null);
 	return false;
}
function order(name , value)
{
	createcookie(name,value);
	window.location.href = document.URL;
}